<?php

class AutoRateConfig_5h
{

    public $betnameArr;
    public $autorateArr;
    public $table_name = "autorate_config_5h";
    public $db;
    public $gametype;

    public function AutoRateConfig_5h($betnameArr, $autorateArr, $gametype = 1)
    {
        global $g_gametype_3d;
        $this->gametype = $gametype;
        $this->tbl = $g_gametype_3d[$gametype]['en'];
        $this->betnameArr = $betnameArr;
        $this->autorateArr = $autorateArr;
        $this->db = new DB();
        $this->table_name = "autorate_config_" . $g_gametype_3d[$gametype]['en'];
    }

    public function checkIfAutoRate($bettype_id)
    {
        return true;
    }

    public function getAutoRateAll()
    {
        global $g_2face_5h;
        $sql = "SELECT * FROM " . $this->table_name . " WHERE 1";
        $result = $this->db->query($sql);
        $reArr = array ();
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
        {
            $tempIdx = $row['bettype_id'];
            $reArr[$tempIdx] = $row;
        }
        if (0 < count($reArr))
        {
            return $reArr;
        }
        foreach ($this->autorateArr as $btype)
        {
            $sql = "INSERT INTO " . $this->table_name . " (bettype_id,subid,typeflag) VALUES (";
            $sql .= $btype . ",0," . ( in_array($btype, $g_2face_5h[$this->gametype]) ? "1" : "0" ) . ")";
            $this->db->query($sql);
        }
    }

    public function updateAutoRate($dataArr)
    {
        foreach ($dataArr as $val)
        {
            $sql = " UPDATE " . $this->table_name . " SET ";
            $sql .= " money =" . $val['money'];
            $sql .= ", downrate =" . $val['downrate'];
            $sql .= ", uprate =" . $val['uprate'];
            $sql .= ", limitrate =" . $val['limitrate'];
            $sql .= ", amount_255 =" . $val['amount_255'];
            $sql .= " WHERE bettype_id=" . $val['id'] . " AND subid=" . $val['subid'] . " AND typeflag =" . $val['typeflag'];
            $this->db->query($sql);
        }
    }

}